package awt;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * @author Mark
 * @version 1.0
 * @date 2020/5/17 9:33
 * @description 测试类
 */
public class AppTest {
    public static void main(String[] args) {
        new MyFrame();
        new Calculator().load();
        new Print().load();
    }
}

class MyFrame extends Frame {
    MyFrame() {
        TextField textField = new TextField();
        add(textField);
        MyAction myAction = new MyAction();
        textField.addActionListener(myAction);
        // 密码设置空
        textField.setEchoChar('*');
        setVisible(true);
        pack();
    }

}

class MyAction implements ActionListener {

    @Override
    public void actionPerformed(ActionEvent e) {
        TextField field = (TextField) e.getSource();
        System.out.println(field.getText());
    }
}

class Calculator extends Frame {
    private TextField num1;
    private TextField num2;
    private TextField num3;

    void load() {
        num1 = new TextField(10);
        num2 = new TextField(10);
        num3 = new TextField(20);
        Button button = new Button("=");
        Label label = new Label("+");
        button.addActionListener(new MyActionListen());
        setLayout(new FlowLayout());
        add(num1);
        add(label);
        add(num2);
        add(button);
        add(num3);
        pack();
        setVisible(true);
    }

    private class MyActionListen implements ActionListener {
        @Override
        public void actionPerformed(ActionEvent e) {
            int n1 = Integer.parseInt(num1.getText());
            int n2 = Integer.parseInt(num2.getText());
            num3.setText("" + (n1 + n2));
            num1.setText("");
            num2.setText("");
        }
    }
}

class Print extends Frame {
    void load() {
        setBounds(200, 200, 300, 200);
        setVisible(true);
    }

    @Override
    public void print(Graphics g) {
        g.setColor(Color.red);
        g.fillOval(100, 100, 100, 100);
    }

}

